1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : courses/classes/class.CourseUtil.php
5 : - Modulgruppe: Veranstaltung
6 : - Beschreibung: Sammlung statischer Methoden.
7 : - Version: 0.2, 03/10/05
8 : - Autor(en): Timo Fuchs <timo.fuchs@mni.fh-giessen.de>
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 :
24 : /**
25 : * In dieser Datei wird die Klasse CourseUtil implementiert.
26 : * @package eStudy.Courses
27 : * @version 0.2, 03/10/05
28 : * @author Timo Fuchs <timo.fuchs@mni.fh-giessen.de>
29 : */
30 :
31 : /** Enthaelt Hilfsfunktion zur Veranstaltungslogistik.
32 : * Alle Methoden sind ohne ein Objekt zu erzeugen benutzbar.
33 : *
34 : * @package eStudy.Courses
35 : * @author Timo Fuchs <timo.fuchs@mni.fh-giessen.de>
36 : * @version 0.2, 03/10/05
37 : */
38 :
39 : if(!defined("START_MONTH_SS")) {
40 : global $settings;
41 :
42 : define("START_MONTH_SS", $settings["start_month_ss"]);
43 : define("START_MONTH_WS", $settings["start_month_ws"]);
44 : }
45 :
46 : class CourseUtil {
47 : /**
48 : * Gibt das aktuelle Semester zurück.
49 : *
50 : * @access public
51 : * @return string Semester in DB-Form (z.B. 04SS)
52 : */
53 : function getCurrentSemester() {
54 : // derzeitigen Semester-Typ ermitteln
55 0 : $currentMonth = (int) strftime("%m"); // derzeitiger Monat
56 0 : if($currentMonth < START_MONTH_SS || $currentMonth >= START_MONTH_WS) {
57 0 : $currentType = "WS";
58 0 : } else {
59 0 : $currentType = "SS";
60 : }
61 0 : $year = (int)strftime("%y");
62 0 : if($currentMonth < START_MONTH_SS)
63 0 : $year = ($year - 1 + 100) % 100; // wegen Jahrhundertgrenze
64 0 : if ($year < 10) $year = "0".$year;
65 0 : return $year.$currentType;
66 : }
67 :
68 : /**
69 : * Gibt eine Listbox zum auswaehlen eines Semesters per echo aus.
70 : *
71 : * @access public
72 : * @static
73 : * @param integer $yearRange Zeitspanne in Jahren,
74 : * die in der Listbox auswaehlbar sein soll.
75 : * @param string $enabledItem Semester, das ausgewaehlt sein soll
76 : * in der Form "WS 03/04" bzw. "SS04".
77 : * @return void
78 : */
79 : function createSemesterListbox($yearRange = 2, $enabledItem = "none") {
80 0 : $currentYear = (int) strftime("%y"); // derzeitiges Jahr
81 0 : $currentMonth = (int) strftime("%m"); // derzeitiger Monat
82 :
83 0 : $listbox = ""; // html-Code der Listbox
84 :
85 : // derzeitigen Semester-Typ ermitteln
86 0 : if($currentMonth < START_MONTH_SS || $currentMonth >= START_MONTH_WS) {
87 0 : $currentType = "WS";
88 0 : } else {
89 0 : $currentType = "SS";
90 : }
91 :
92 : // Anfangsjahr-und semester-Typ ermitteln
93 0 : if($enabledItem === "none") {
94 0 : $startYear = $currentYear;
95 0 : $startType = $currentType;
96 0 : } else {
97 0 : $enabledYear = (int) substr($enabledItem, 3, 2);
98 0 : $enabledType = substr($enabledItem, 0, 2);
99 0 : if($enabledYear < $currentYear) {
100 0 : $startYear = $enabledYear;
101 0 : $startType = $enabledType;
102 0 : $yearRange = $yearRange + $currentYear - $enabledYear;
103 0 : } elseif($enabledYear == $currentYear) {
104 0 : $startYear = $currentYear;
105 0 : if($enabledType === "SS" || $currentType === "SS") {
106 0 : $startType = $currentType;
107 0 : } else {
108 0 : $startType = "WS";
109 : }
110 0 : } else {
111 0 : $startYear = $currentYear;
112 0 : $startType = $currentType;
113 : }
114 :
115 : }
116 0 : if($startType === "WS") {
117 0 : $startYear--;
118 0 : }
119 :
120 : // Listbox konstruieren.
121 0 : $listbox .= "<select name='semester'>";
122 0 : $yearCount = 0; // zaehlt die bereits angezeigten Jahre
123 0 : $tempType = $startType; // temporaerer Semester-Typ
124 :
125 : // Options konstruieren.
126 0 : while($yearCount <= $yearRange) {
127 0 : $item = $tempType;
128 0 : $item .= " ";
129 0 : $item .= strftime("%y", mktime(0,0,0,1,1,$startYear+$yearCount));
130 0 : if($tempType === "WS") {
131 0 : $item .= "/";
132 0 : $item .= strftime("%y", mktime(0,0,0,1,1,$startYear+$yearCount+1));
133 0 : $yearCount++;
134 0 : $tempType = "SS";
135 0 : } else {
136 0 : $tempType = "WS";
137 : }
138 0 : $listbox .= "<option value='".$item."'";
139 0 : if($item === $enabledItem) {
140 0 : $listbox .= " selected='selected'";
141 0 : }
142 0 : $listbox .= ">".$item."</option>";
143 0 : }
144 :
145 0 : $listbox .= "</select>";
146 :
147 : // Listbox ausgeben.
148 0 : echo $listbox;
149 0 : }
150 : }
151 :
|